package com.csdj.t309tgspringboot.service;

import com.csdj.t309tgspringboot.entity.Post;
import com.csdj.t309tgspringboot.entity.PostExample;
import com.csdj.t309tgspringboot.mapper.PostMapper;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service
public class PostService implements IPostService{

    @Resource
    private PostMapper postMapper;

    @Override
    public int insertPost(Post post) {
        Integer num = postMapper.insert(post);
        if(num>0){
            return num;
        }
        return 0;
    }

    @Override
    public Post selPost(Integer userId,Integer id) {
        PostExample postExample = new PostExample();
        postExample.createCriteria().andUserIdEqualTo(userId).andIdEqualTo(id);
        Post post = postMapper.selectByExample(postExample).get(0);
        return post;
    }

    @Override
    public List<Post> selPosts() {
        PostExample postExample = new PostExample();
        postExample.createCriteria();
        List<Post> post = postMapper.selectByExample(postExample);
        return post;
    }
}
